#!/usr/bin/env python
# -*- coding:utf-8 -*-

import json
import requests
import base64
import io
from io import BytesIO
from PIL import Image
from sys import version_info
from lxml import etree

# 流程：
# 1、验证码识别，获取验证码图片的文字数据
# 2、对post请求进行发送（）
# 3、对响应数据进行持久化

# 1.对验证码图片进行捕获和识别

headers = {
        'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Mobile Safari/537.36'
    }
url = 'http://www.renren.com/'
page_text = requests.get(url=url,headers=headers).text
tree = etree.HTML(page_text)
code_img_src = tree.xpath('//*[@id="verifyPic_login"]/@src')[0]
code_img_data = requests.get(url=code_img_src,headers=headers).content
with io.open("./file/code.jpg","wb") as fp:
    fp.write(code_img_data)

# 使用打码平台进行识别

# 登录post

# 验证response的status判断登录是否成功

# 发起post请求，调用相关接口

